﻿#include "screenshot.h"
#include "screen.h"
#include "editimagewidget.h"

#include <QDebug>
#include <QImageReader>
#include <QObject>

QObject* startCapture(CaptureCB cb)
{
    Screen* s = new Screen();
    s->showFullScreen();
    s->Init();

    QObject::connect(s,&Screen::finished,[=](int code){
       cb.finishCB(code);
    });

    QObject::connect(s,&Screen::forward,[=](QPixmap img){
       cb.forwordCB(img);
    });

    return s;
}

QObject* startEdit(QString path, ImageEditCB cb)
{
    QImageReader reader(path);
    reader.setAutoTransform(true);	// 自动调整图片角度
    QImage img = reader.read();
    if(img.isNull()){
        qDebug() << "startEdit error:" << path;
        return nullptr;
    }

    EditImageWidget *dlg = new EditImageWidget(img);

    QObject::connect(dlg,&EditImageWidget::finished,[=](int code){
       cb.finishCB(code);
    });

    QObject::connect(dlg,&EditImageWidget::forward,[=](QPixmap img){
       cb.forwordCB(img);
    });

    dlg->show();
    dlg->moveControls();
    dlg->moveToScreenCenter();

    return dlg;
}
